Currently, computer program source code often contains constructs called "switch statements" which are multi-way branches. When such statements, in the form of object code, run in real-time, the branch that is taken depends on the value of the data that is present at that time. When a switch statement is inside a program loop, there may be a pattern to which branch is selected branch as the loop is executed. Such patterns can be used, if predictable, to optimize system performance, particularly as the code is being compiled from the source program.
However, a branch statement is expensive (in terms of machine cycles) on modern computer systems. This is particularly so when a branch is an indirect branch, meaning that the branch is unpredictable as to where it might go. Most instructions today can execute in a cycle or less so that often several instructions could execute during the same cycle. But when a branch statement is encountered, it might take perhaps six cycles to figure out where the target of the branch is, i.e., which branch is being followed and to obtain the necessary data from memory.
Another problem with branches, other than the fact that they are expensive to execute, is that they tend to introduce bottlenecks where the code optimizer (during the compiling stage) is not able to do as effective a job as it might otherwise do. When the compiler optimizer encounters a branch, it cannot effectively combine instructions from beyond that branch with instructions from prior to that branch. This then does not allow the compiled code to be properly optimized for run-time performance.
Therefore, there is a need in the art for a system and method for optimizing run-time code in the face of branches and switch statements.